package com.yuma.schedule;

import java.time.LocalDateTime;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduleExecutor {
    public static void main(String[] args) {
        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(10);

//        scheduledThreadPool.schedule(()->{
//            System.out.println("time:" + LocalDateTime.now());
//        },1L, TimeUnit.SECONDS);

        scheduledThreadPool.scheduleAtFixedRate(()->{
            System.out.println("time:" + LocalDateTime.now());
        },1L, 1L, TimeUnit.SECONDS);

        // 手动关闭线程池
        //scheduledThreadPool.shutdown();
    }
}
